You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by ch...@ebi.ac.uk on 2007/05/03 18:18:39 UTC

dynamic c:import

In some cases, I want to dynamically import fragment of page. Such as:
<c:import url="#{masterBean.action}" />

I used <h:outputText value="#{masterBean.action}"/> to test
masterBean.action returns correct value, for instance, main.jsp.

But it seem it could not be imported in this way, I was told:
The requested resource (/myproject-name/#{masterBean.action}) is not
available.

Could anyone give me any clue how to deal with this? Or an alternate
solution.

Appreciate.


Re: dynamic c:import

Posted by Simon Kitching <si...@rhe.co.nz>.
chenli@ebi.ac.uk wrote:
>> chenli@ebi.ac.uk wrote:
>>> In some cases, I want to dynamically import fragment of page. Such as:
>>> <c:import url="#{masterBean.action}" />
>>>
>>> I used <h:outputText value="#{masterBean.action}"/> to test
>>> masterBean.action returns correct value, for instance, main.jsp.
>>>
>>> But it seem it could not be imported in this way, I was told:
>>> The requested resource (/myproject-name/#{masterBean.action}) is not
>>> available.
>>>
>>> Could anyone give me any clue how to deal with this? Or an alternate
>>> solution.
>> When using jsp1.1:
>> * the #{..} syntax is only processed within an attribute of a JSF tag.
>> * the ${..} syntax is not permitted within an attribute of a JSF tag
>>
>> You can probably change to using:
>>   <c:import url="${masterBean.action}"/>
>> The only difference is that the masterBean object must already exist, as
>> the JSP ${...} stuff won't create a bean from the JSF "managed beans"
>> definitions in the faces config file. As long as there is a reference to
>> #{masterBean} somewhere earlier in the same page the bean will exist so
>> that should be ok.
>>
>> Note by the way that JSTL tags generally don't work well with JSF1.1. In
>> particular, c:forEach and c:if are a bad idea. However I *think*
>> c:import would be ok as it doesn't have any conditional behaviour.
> 
> Thank you very much, Simon,
> 
> I found another solution on BalusC's
> http://balusc.xs4all.nl/srv/dev-jep-djs.html . It works good.
> 
> I also tried to replace # with $. But didn't get luck.
> 

That article appears flawed to me. It depends on calling
    new MyBean();
rather than creating it via the managed bean mechanism.

This means that
(a) it's never placed into any scope so other references using #{..} or 
${..} syntax will end up returning a *different* instance.
(b) the instance doesn't get any of the injected values defined in the 
managed bean declaration in the faces config file.
(c) the page needs to know what the concrete type of name masterBean is. 
That's not fatal, but is not very clean - that info is then present in 
two totally different locations; the jsp page and the faces config file.

I think using
   <c:import url="${masterBean.action}"/>
is much nicer. If it's not working for you then I presume that the 
masterBean object has not yet been created. That can probably be fixed 
by putting this before the c:import tag:

   <h:outputText style="display:none" value="#{masterBean.class}"/>

This is forcing a lookup of the masterBean object, which will force it 
to be created if it doesn't exist (and inserted into the appropriate 
scope where the JSP expression can then find it). Unfortunately there is 
no tag (AFAIK) that can cause a read of a property without generating 
*some* output, but outputting some text marked as display:none is 
effectively the same.

Regards,

Simon

Re: dynamic c:import

Posted by ch...@ebi.ac.uk.
> chenli@ebi.ac.uk wrote:
>> In some cases, I want to dynamically import fragment of page. Such as:
>> <c:import url="#{masterBean.action}" />
>>
>> I used <h:outputText value="#{masterBean.action}"/> to test
>> masterBean.action returns correct value, for instance, main.jsp.
>>
>> But it seem it could not be imported in this way, I was told:
>> The requested resource (/myproject-name/#{masterBean.action}) is not
>> available.
>>
>> Could anyone give me any clue how to deal with this? Or an alternate
>> solution.
>
> When using jsp1.1:
> * the #{..} syntax is only processed within an attribute of a JSF tag.
> * the ${..} syntax is not permitted within an attribute of a JSF tag
>
> You can probably change to using:
>   <c:import url="${masterBean.action}"/>
> The only difference is that the masterBean object must already exist, as
> the JSP ${...} stuff won't create a bean from the JSF "managed beans"
> definitions in the faces config file. As long as there is a reference to
> #{masterBean} somewhere earlier in the same page the bean will exist so
> that should be ok.
>
> Note by the way that JSTL tags generally don't work well with JSF1.1. In
> particular, c:forEach and c:if are a bad idea. However I *think*
> c:import would be ok as it doesn't have any conditional behaviour.

Thank you very much, Simon,

I found another solution on BalusC's
http://balusc.xs4all.nl/srv/dev-jep-djs.html . It works good.

I also tried to replace # with $. But didn't get luck.


Re: dynamic c:import

Posted by Simon Kitching <si...@rhe.co.nz>.
chenli@ebi.ac.uk wrote:
> In some cases, I want to dynamically import fragment of page. Such as:
> <c:import url="#{masterBean.action}" />
> 
> I used <h:outputText value="#{masterBean.action}"/> to test
> masterBean.action returns correct value, for instance, main.jsp.
> 
> But it seem it could not be imported in this way, I was told:
> The requested resource (/myproject-name/#{masterBean.action}) is not
> available.
> 
> Could anyone give me any clue how to deal with this? Or an alternate
> solution.

When using jsp1.1:
* the #{..} syntax is only processed within an attribute of a JSF tag.
* the ${..} syntax is not permitted within an attribute of a JSF tag

You can probably change to using:
  <c:import url="${masterBean.action}"/>
The only difference is that the masterBean object must already exist, as 
the JSP ${...} stuff won't create a bean from the JSF "managed beans" 
definitions in the faces config file. As long as there is a reference to 
#{masterBean} somewhere earlier in the same page the bean will exist so 
that should be ok.

Note by the way that JSTL tags generally don't work well with JSF1.1. In 
particular, c:forEach and c:if are a bad idea. However I *think* 
c:import would be ok as it doesn't have any conditional behaviour.

Regards,

Simon

Re: dynamic c:import

Posted by Andrew Robinson <an...@gmail.com>.
In case you are using facelets or ajax4jsf or could consider using them:

If you are using facelets, use ui:import
If you are using ajax4jsf, use a4j:import

-Andrew

On 5/3/07, chenli@ebi.ac.uk <ch...@ebi.ac.uk> wrote:
> In some cases, I want to dynamically import fragment of page. Such as:
> <c:import url="#{masterBean.action}" />
>
> I used <h:outputText value="#{masterBean.action}"/> to test
> masterBean.action returns correct value, for instance, main.jsp.
>
> But it seem it could not be imported in this way, I was told:
> The requested resource (/myproject-name/#{masterBean.action}) is not
> available.
>
> Could anyone give me any clue how to deal with this? Or an alternate
> solution.
>
> Appreciate.
>
>