0

The error "/resources/components/hostForm.xhtml @25,84 value="#{cc.attrs.host.hostName}": Target Unreachable, 'host' returned null" occurs after I added

 <f:validateLength minimum="1" maximum="200"/> 

to an inputText field in a custom tag. Without the validation everything works well.

     <!-- INTERFACE -->
    <composite:interface>
        <composite:attribute name="host" />
        <composite:attribute name="prefix" />
    </composite:interface>
    <!-- IMPLEMENTATION -->
    <composite:implementation>
        <h:panelGrid columns="3" columnClasses="titleCell">
            <h:outputLabel for="#{cc.attrs.prefix}hostName" value="Host Name" />
            <h:inputText id="#{cc.attrs.prefix}hostName" value="#{cc.attrs.host.hostName}">
                <f:validateLength minimum="1" maximum="200"/>
                <rich:validator />
            </h:inputText>
            <rich:message for="#{cc.attrs.prefix}hostName" />
        </h:panelGrid>
    </composite:implementation>

The field is declared as

  @Named
  @Produces
  private Host newHost;

The custom tag invocation:

<my:hostForm prefix="c" host="#{newHost}"/>

What do I need to change to get this work with validation?

EDIT:

The Bean already has the @ConversationScoped annotation. Adding a @ConversationScoped annotation to the fields leads to this error:

hostForm.xhtml @20,74 value="#{cc.attrs.host.id}": org.jboss.weld.exceptions.IllegalProductException: WELD-000052 Cannot return null from a non-dependent producer method: [field] @Named @ConversationScoped @Produces

4

2 に答える 2

2

それにスコープを追加してみてください。おそらくリクエストまたは会話です。あなたが持っているのは、デフォルトのスコープです。これはnew、インスタンスが必要になるたびにスコープを作成するようなものです。

于 2013-02-01T14:22:10.533 に答える
0

注釈を属性からゲッターに移動し、自分でオブジェクトをインスタンス化しました。これは機能します。

@Produces
@Named("newHost")
public Host getNewHost() {
    if ( newHost == null ) {
        newHost = new Host();
    }
    return newHost;
}

https://community.jboss.org/thread/179527

于 2013-02-01T15:26:32.707 に答える