java.lang.NullPointerException at org.primefaces.extensions.component.remotecommand.RemoteCommandRenderer.decode

StackOverflow https://stackoverflow.com/questions/15427152

Domanda

On the Facelet, I try to use <pe:remoteCommand> to update backingbean value:

<pe:remoteCommand name="saveMapArea" process="@this" actionListener="#{defineMapArea.createMapArea}">
    <pe:assignableParam name="areaString"  assignTo="#{defineMapArea.tagMapArea.mapArea}"/>  
    <pe:assignableParam name="areaName" assignTo="#{defineMapArea.tagMapArea.name}" />
    <pe:assignableParam name="castId" assingTo="#{defineMapArea.tagMapArea.castId}" />           
</pe:remoteCommand>

castId value is retrieved from a dropdown list by jQuery when user clicks submit button, the code for dropdown list is:

<h:selectOneMenu id="area_assign_device">
    <f:selectItem itemLabel="Select Icast" itemValue="" />
    <f:selectItems value="#{defineMapArea.castList}" var="cast" itemLabel="#{cast.name}" itemValue="#{cast.castId}"/>
</h:selectOneMenu>

the code for submit button is:

<p:commandButton value="Submit" type="button" onclick="CreateArea.saveArea()"/>

the code for calling remotecommand 'saveMapArea' is:

saveArea : function() {
    if(CreateArea.validate()) {
        // ...some other code to init map area...

        var name=jQuery('#area_name_text').val();
        var castId=jQuery('#area_assign_device').val();
        saveMapArea(mapArea, name, castId);
        CreateArea.points = [];
    }              
}

and my backing bean is:

@ManagedBean
@RequestScoped
public class DefineMapArea extends BaseJsfBean {

    private static final long serialVersionUID = 1L;
    private static Log log = LogFactory.getLog(DefineMapArea.class);
    private TagMapArea tagMapArea;
    private List<TagMapArea> areaList;
    private String areaListJson;

    @ManagedProperty(value="#{tagCustomService}")
    private ITagCustomService tagCustomService;  

    @Override
    protected void init() throws Exception {
        // ..some initializations...
    }  

    public void createMapArea() {
        log.info("Area Persisting : " + tagMapArea.getMapArea());               
        tagMapArea.setTagMapImageId(2);
        tagMapArea.setMapAreaType("test");
        tagMapArea.setDescription("test");
    }

    // ....all the getters and setters....
}

TagMapArea is the JPA entity, the part including castId field is:

@Column(name = "cast_id", nullable = false)
protected Integer castId;

@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="cast_id", nullable=false, insertable=false, updatable=false)
protected TagCast cast;    

The problem is when I click submit button, it throws a NullPointerException like this:

java.lang.NullPointerException
    at org.primefaces.extensions.component.remotecommand.RemoteCommandRenderer.decode(RemoteCommandRenderer.java:82)
    at javax.faces.component.UIComponentBase.processDecodes(UIComponentBase.java:1377)
    at org.apache.myfaces.context.servlet.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:731)
    at org.apache.myfaces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:214)
    at javax.faces.component.UIComponent.visitTree(UIComponent.java:932)

I'm pretty sure this is caused by castId field in the remote command, because if I remove that field, it works ok. I am confused why the selected value retrieved from the dropdown list doesn't get sent to the remotecommand. Does anyone konw where the problem is?

È stato utile?

Soluzione

Still not sure where went wrong ,but i found a walk around, instead of using remote command in primefaces extentions, I tried the original remote command in primefaces and it works.

The code after change is:

<p:remoteCommand name="saveMapArea" actionListener="#{defineMapArea.createMapArea}" />

and for the javascript part, it becomes:

saveMapArea([{name:'mapArea', value:mapArea},{name:'name',value:name},{name:'castId',value:castId}]);

in the backing bean's createMapArea method, the code snippet to get values is:

    FacesContext context = FacesContext.getCurrentInstance();
    Map map = context.getExternalContext().getRequestParameterMap();
    String mapArea = (String)map.get("mapArea");
    String name = (String)map.get("name");
    String castId = (String)map.get("castId");
    log.info("Area Persisting : " + mapArea);
    log.info("name: " + name + " castId: " + castId);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top