primefaces '<p:selectOneMenu'



我一直得到这个错误addAddress:状态:验证错误:使用<p:selectOneMenu时值无效。我尝试使用id并摆脱了转换器,它做同样的事情。我试着调试。发现转换运行了两次,最后一次检查空白值并返回null/false。我做错了什么?如果需要更多的细节请告诉我。

代码如下

转换器

    @FacesConverter(value = "statemasterconverter", forClass = Statemaster.class)
public class StateConverter implements Converter {
    public String getAsString(FacesContext context, UIComponent component,
            Object value) {
        return ConversionHelper.getAsString(value);
    }
    public Object getAsObject(FacesContext context, UIComponent component,
            String value) {
        return ConversionHelper.getAsObject(Statemaster.class, value);
    }
}

转换辅助

public final class ConversionHelper {
    private ConversionHelper() {
    }
    @SuppressWarnings("unchecked")
    public static <T> T getAsObject(Class<T> returnType, String value) {
        BigDecimal id = BigDecimal.ZERO;
        if (returnType == null) {
            throw new NullPointerException(
                    "Trying to getAsObject with a null return type.");
        }
        if (value == null) {
            throw new NullPointerException(
                    "Trying to getAsObject with a null value.");
        }
        try {
            id = BigDecimal.valueOf(Long.parseLong(value));
        } catch (NumberFormatException nfe) {
            return null;
        }
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            T r = (T) session.load(returnType, id);
            if (r != null)
                Hibernate.initialize(r);
            return r;
        } catch (HibernateException e) {
            e.printStackTrace();
        } finally {
            session.close();
        }
        return null;
    }
    public static String getAsString(Object value) {
        if (value instanceof Gendermaster) {
            Gendermaster result = (Gendermaster) value;
            return String.valueOf(result.getGenderid());
        } else if (value instanceof Salutationmaster) {
            Salutationmaster result = (Salutationmaster) value;
            return String.valueOf(result.getSalutationid());
        } else if (value instanceof Countrymaster) {
            Countrymaster result = (Countrymaster) value;
            return String.valueOf(result.getCountryid());
        } else if (value instanceof Statemaster) {
            Statemaster result = (Statemaster) value;
            return String.valueOf(result.getStateid());
        }
        return null;
    }
}

XHTML代码

                    <p:row>
                        <p:column>
                        Country
                    </p:column>
                        <p:column>
                            <p:selectOneMenu id="country"
                                value="#{customerBean.country.countryid}" required="true">
                                <f:selectItem itemLabel="Select Country" itemValue="" />
                                <f:selectItems value="#{customerBean.countrydropdown}"
                                    var="countrymaster"
                                    itemLabel="#{countrymaster.countryname} - #{countrymaster.countrycodeNn}"
                                    itemValue="#{countrymaster.countryid}" />
                                <p:ajax update="states"
                                    listener="#{customerBean.updateStates()}" />
                            </p:selectOneMenu>
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column>
                        State
                    </p:column>
                        <p:column>
                            <p:selectOneMenu id="states" required="true"
                                value="#{customerBean.state}" converter="statemasterconverter">
                                <f:selectItem itemValue="" itemLabel="Select State" />
                                <f:selectItems value="#{customerBean.statedropdown}"
                                    var="statemaster"
                                    itemLabel="#{statemaster.statename} - #{statemaster.statecode}"
                                    itemValue="#{statemaster}" />
                            </p:selectOneMenu>
                        </p:column>
                    </p:row>
                        <p:commandButton id="saveBtn" value="Save Salutation"
                            update="msgs"
                                style="float: left;" icon="ui-icon-disk"
                                actionListener="#{customerBean.saveAddress()}" ajax="true" />
                        </p:column>

在Ajax中使用event="valueChange"并尝试通过update="@form"更新整个表单。如果上面的代码不工作,然后尝试update=":id:id"更新标签内的标签搜索id。让我们考虑下面的代码:

<h:form id="myForm">
    <h:sometag id="ineer1">
        <p:ajax update="ineer3"/>// it is **not work**
        <p:ajax update=":myForm:ineer2:ineer2"/>// it is **work**
    </h:sometag>
    <h:sometag id="ineer2">
        <h:someoutfield id="ineer3"/>
     </h:sometag>
<h:/form> 

它正在工作在我的结束,如果不工作,然后让我知道。很乐意帮忙:)

相关内容

  • 没有找到相关文章

最新更新