当前位置: 代码迷 >> Web前端 >> Richfaces 四 ExtendedPartialViewContextImpl swallows exceptions
  详细解决方案

Richfaces 四 ExtendedPartialViewContextImpl swallows exceptions

热度:638   发布时间:2014-01-09 23:07:34.0
Richfaces 4 ExtendedPartialViewContextImpl swallows exceptions

Method public VisitResult visit(VisitContext context, UIComponent target) of class ExtendedPartialViewContextImpl swallows exceptions. I think exceptions should be wrapped inside a FaceException and propagated. This class http://java.net/projects/mojarra/sources/svn/content/trunk/jsf-ri/src/main/java/com/sun/faces/context/PartialViewContextImpl.java seems to have served as a model for the RF one, but the RF class inadvertently chose to swallow exceptions instead of propagating them up. This causes unpredictable behaviour, such as system being stuck in the browser.

Richfaces 4 ExtendedPartialViewContextImpl:

public VisitResult visit(VisitContext context, UIComponent target) {
??????????? String metaComponentId = (String) ctx.getAttributes().get(ExtendedVisitContext.META_COMPONENT_ID);
??????????? if (metaComponentId != null) {
??????????????? MetaComponentEncoder encoder = (MetaComponentEncoder) target;
??????????????? try {
??????????????????? encoder.encodeMetaComponent(ctx, metaComponentId);
??????????????? } catch (Exception e) {
??????????????????? logException(e);
??????????????? }
??????????? } else {
??????????????? PartialResponseWriter writer = ctx.getPartialViewContext().getPartialResponseWriter();

??????????????? try {
??????????????????? writer.startUpdate(target.getClientId(ctx));
??????????????????? try {
??????????????????????? // do the default behavior...
??????????????????????? target.encodeAll(ctx);
??????????????????? } catch (Exception ce) {
??????????????????????? logException(ce);
??????????????????? }
??????????????????? writer.endUpdate();
??????????????? } catch (IOException e) {
??????????????????? logException(e);
??????????????? }
??????????? }

??????????? // Once we visit a component, there is no need to visit
??????????? // its children, since processDecodes/Validators/Updates and
??????????? // encodeAll() already traverse the subtree. We return
??????????? // VisitResult.REJECT to supress the subtree visit.
??????????? return VisitResult.REJECT;
??????? }


I just found an older version of Sun's Mojarra where they had the same issue, but the newer versions seem to have fixed it.

JSF 2.1.7 PartialViewContextImpl:

public VisitResult visit(VisitContext context, UIComponent comp) {
??????????? try {

??????????????? if (curPhase == PhaseId.APPLY_REQUEST_VALUES) {

??????????????????? // RELEASE_PENDING handle immediate request(s)
??????????????????? // If the user requested an immediate request
??????????????????? // Make sure to set the immediate flag here.

??????????????????? comp.processDecodes(ctx);
??????????????? } else if (curPhase == PhaseId.PROCESS_VALIDATIONS) {
??????????????????? comp.processValidators(ctx);
??????????????? } else if (curPhase == PhaseId.UPDATE_MODEL_VALUES) {
??????????????????? comp.processUpdates(ctx);
??????????????? } else if (curPhase == PhaseId.RENDER_RESPONSE) {

??????????????????? PartialResponseWriter writer = ctx.getPartialViewContext().getPartialResponseWriter();

??????????????????? writer.startUpdate(comp.getClientId(ctx));
??????????????????? try {
??????????????????????? // do the default behavior...
??????????????????????? comp.encodeAll(ctx);
??????????????????? }
??????????????????? catch (Exception ce) {
??????????????????????? if (LOGGER.isLoggable(Level.SEVERE)) {
??????????????????????????? LOGGER.severe(ce.toString());
??????????????????????? }
??????????????????????? if (LOGGER.isLoggable(Level.FINE)) {
??????????????????????????? LOGGER.log(Level.FINE,
??????????????????????????? ce.toString(),
??????????????????????????? ce);
??????????????????????? }
??????????????????? }
??????????????????? writer.endUpdate();
??????????????? }
??????????????? else {
??????????????????? throw new IllegalStateException("I18N: Unexpected " +
??????????????????????????????????????????????????? "PhaseId passed to " +
????????????????????????????????????????????? " PhaseAwareContextCallback: " +
??????????????????????????????????????????????????? curPhase.toString());
??????????????? }
??????????? }
??????????? catch (IOException ex) {
??????????????? ex.printStackTrace();
??????????? }

??????????? // Once we visit a component, there is no need to visit
??????????? // its children, since processDecodes/Validators/Updates and
??????????? // encodeAll() already traverse the subtree.? We return
??????????? // VisitResult.REJECT to supress the subtree visit.
??????????? return VisitResult.REJECT;
??????? }

JSF 2.1.17 PartialViewContextImpl:
public VisitResult visit(VisitContext context, UIComponent comp) {
??????????? try {

??????????????? if (curPhase == PhaseId.APPLY_REQUEST_VALUES) {

??????????????????? // RELEASE_PENDING handle immediate request(s)
??????????????????? // If the user requested an immediate request
??????????????????? // Make sure to set the immediate flag here.

??????????????????? comp.processDecodes(ctx);
??????????????? } else if (curPhase == PhaseId.PROCESS_VALIDATIONS) {
??????????????????? comp.processValidators(ctx);
??????????????? } else if (curPhase == PhaseId.UPDATE_MODEL_VALUES) {
??????????????????? comp.processUpdates(ctx);
??????????????? } else if (curPhase == PhaseId.RENDER_RESPONSE) {
??????????????????? PartialResponseWriter writer = ctx.getPartialViewContext().getPartialResponseWriter();
??????????????????? writer.startUpdate(comp.getClientId(ctx));
??????????????????? // do the default behavior...
??????????????????? comp.encodeAll(ctx);?????????
??????????????????? writer.endUpdate();
??????????????? } else {
??????????????????? throw new IllegalStateException("I18N: Unexpected " +
??????????????????????????????????????????????????? "PhaseId passed to " +
????????????????????????????????????????????? " PhaseAwareContextCallback: " +
??????????????????????????????????????????????????? curPhase.toString());
??????????????? }
??????????? }
??????????? catch (IOException ex) {
??????????????? if (LOGGER.isLoggable(Level.SEVERE)) {
??????????????????? LOGGER.severe(ex.toString());
??????????????? }
??????????????? if (LOGGER.isLoggable(Level.FINE)) {
??????????????????? LOGGER.log(Level.FINE,
??????????????????? ex.toString(),
??????????????????? ex);
??????????????? }
??????????????? throw new FacesException(ex);
??????????? }

??????????? // Once we visit a component, there is no need to visit
??????????? // its children, since processDecodes/Validators/Updates and
??????????? // encodeAll() already traverse the subtree.? We return
??????????? // VisitResult.REJECT to supress the subtree visit.
??????????? return VisitResult.REJECT;
??????? }

?

  相关解决方案