You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Chris Mylonas <ch...@opencsta.org> on 2013/12/18 03:48:41 UTC

My form error message, include link to a page from java class

Hi Tapestry Users,

What is the best way to include a link to a page from the java class?

I have a form, returning an error that states: "The ip address you entered
is public and in use - please try again or search for it to see it's
current use"

I would like to put a link in that error message to the search page.

It's just a standard form.recordErrors

                form.recordError(commonNameField, "The ip address you
entered is public and in use - please try again or search (PUT LINK HERE TO
SEARCH PAGE) for it to see it's current use");

Cheers
Chris

Re: My form error message, include link to a page from java class

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 18 Dec 2013 19:54:51 -0200, Chris Mylonas <ch...@opencsta.org>  
wrote:

> Thanks, but no again.
>
>
> form.recordError(commonNameField, "The ip address you entered is public  
> and
> in use - please try again or search for it ${" + link.toAbsoluteURI() +  
> "}"
> );
>
> renders this as a string, and without the expansion-y ${} it's just plain
> old text.
> ${http://hplaptop:8080/MetwideSubnetsWeb/search/ipaddress}

The only place Tapestry does expansions is in templates and a couple  
annotations involving symbol values. But the expansion above would be  
wrong anyway and fail with an exception.

> Can the Corelib.Errors component, rather than just being
> <t:errors />
> be expanded to hold a <t:if> and ${expansion} for use in case of error?

Nope. I vaguely recall a JIRA issue asking for Form.recordError() (which  
actually delegates to ValidationTracker.recordError()) to accept HTML and  
not encode it.

-- 
Thiago H. de Paula Figueiredo
Tapestry, Java and Hibernate consultant and developer
http://machina.com.br

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: My form error message, include link to a page from java class

Posted by Chris Mylonas <ch...@opencsta.org>.
Beauty, I'll give that a shot - sounds like what I want to do.


Thanks Taha


On Thu, Dec 19, 2013 at 11:14 AM, Taha Siddiqi <ta...@gmail.com>wrote:

> Oops! Sorry I misunderstood your question.
>
> If you want a clickable link, I don't think Errors component can do that.
>
>
> http://tapestry.apache.org/5.3/apidocs/src-html/org/apache/tapestry5/corelib/components/Errors.html
>
> The text message is written as writer.write() rather than writer.writeRaw()
>
> You can create a new component for errors by copying the code from Errors
> and using writer.writeRaw
>
>
> http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/MarkupWriter.html#writeRaw(java.lang.String)
>
>
> then you can pass html string to form.recordError()
>
> "<a href='" + link.toAbsoluteURI() + "'>here</a>"
>
>
> regards
> Taha
>
> On Dec 19, 2013, at 3:24 AM, Chris Mylonas wrote:
>
> > Thanks, but no again.
> >
> >
> > form.recordError(commonNameField, "The ip address you entered is public
> and
> > in use - please try again or search for it ${" + link.toAbsoluteURI() +
> "}"
> > );
> >
> > renders this as a string, and without the expansion-y ${} it's just plain
> > old text.
> > ${http://hplaptop:8080/MetwideSubnetsWeb/search/ipaddress}
> >
> >
> > Similarly putting an <a href=\" + Link#toAbsoluteURI + \">blah</a>  just
> > outputs text, like this:
> >
> > &lt;a href="${http://hplaptop:8080/MetwideSubnetsWeb/search/ipaddress
> }"&gt;
> > blah&lt;/a&gt;
> >
> > (I've copy pasted html src.  In case it's not viewable, tapestry has
> > converted the less than and greater than in the previous sentence to
> > ampersand+elle+tee+semi-colon and ampersand+gee+tee+semi-colon,
> > respectively)
> >
> >
> > Form#recordError accepts a String.  So I'm starting to think this String
> is
> > just rendered without any smarts to it.  Can't really fuse in a
> > MarkupWriter, because recordError just accepts String.
> >
> >
> > Any further ideas?
> >
> > Can the Corelib.Errors component, rather than just being
> > <t:errors />
> >
> > be expanded to hold a <t:if> and ${expansion} for use in case of error?
> >
> > Cheers
> > Chris
> >
> >
> > On Thu, Dec 19, 2013 at 2:26 AM, Taha Siddiqi <tawus.tapestry@gmail.com
> >wrote:
> >
> >> Use Link#toAbsoluteURI() or Link#toURI() depending on your need( I think
> >> here toAbsoluteURI() is more appropriate)
> >>
> >>
> >> On Dec 18, 2013, at 8:32 PM, Chris Mylonas wrote:
> >>
> >>> Thanks Taha - I was looking at the Link Component FAQ earlier
> scratching
> >> my
> >>> head.  It spits out the text for the link, not a html link.
> >>>
> >>> So I tried this:
> >>>           Link link = linkSource.createPageRenderLink(IPAddress.class);
> >>>           if (ni != null) {
> >>>               form.recordError(commonNameField, "The ip address you
> >>> entered is public and in use - please try again or search for it <a
> >>> href=\"" + link + "\">HERE</a>" );
> >>>           }
> >>>
> >>> and that just spits out text too.
> >>>
> >>>
> >>>
> >>> Given it's 2am, I'm going to bed.  Try again tomorrow with a fresh
> head.
> >>> Cheers,
> >>> Chris
> >>>
> >>>
> >>>
> >>>
> >>> On Wed, Dec 18, 2013 at 4:25 PM, Taha Hafeez Siddiqi <
> >>> tawus.tapestry@gmail.com> wrote:
> >>>
> >>>> You can use
> >>>>
> >>>>
> >>>>
> >>
> http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/services/PageRenderLinkSource.html#createPageRenderLink(java.lang.Class)
> >>>>
> >>>>
> >>>> @Inject
> >>>> private PageRenderLinkSource linkSource
> >>>>
> >>>> form.recordError(someField, "my link is " +
> >>>> linkSource.createPageRenderLink(MyPage.class));
> >>>>
> >>>> there are other variants of createPageRenderLink which can take
> context
> >>>> parameters.
> >>>>
> >>>> regards
> >>>> Taha
> >>>>
> >>>> On 18-Dec-2013, at 8:18 AM, Chris Mylonas <ch...@opencsta.org> wrote:
> >>>>
> >>>>> Hi Tapestry Users,
> >>>>>
> >>>>> What is the best way to include a link to a page from the java class?
> >>>>>
> >>>>> I have a form, returning an error that states: "The ip address you
> >>>> entered
> >>>>> is public and in use - please try again or search for it to see it's
> >>>>> current use"
> >>>>>
> >>>>> I would like to put a link in that error message to the search page.
> >>>>>
> >>>>> It's just a standard form.recordErrors
> >>>>>
> >>>>>              form.recordError(commonNameField, "The ip address you
> >>>>> entered is public and in use - please try again or search (PUT LINK
> >> HERE
> >>>> TO
> >>>>> SEARCH PAGE) for it to see it's current use");
> >>>>>
> >>>>> Cheers
> >>>>> Chris
> >>>>
> >>>>
> >>
> >>
>
>

Re: My form error message, include link to a page from java class

Posted by Taha Siddiqi <ta...@gmail.com>.
Oops! Sorry I misunderstood your question.

If you want a clickable link, I don't think Errors component can do that.

http://tapestry.apache.org/5.3/apidocs/src-html/org/apache/tapestry5/corelib/components/Errors.html

The text message is written as writer.write() rather than writer.writeRaw()

You can create a new component for errors by copying the code from Errors and using writer.writeRaw 

http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/MarkupWriter.html#writeRaw(java.lang.String)


then you can pass html string to form.recordError()

"<a href='" + link.toAbsoluteURI() + "'>here</a>"


regards
Taha

On Dec 19, 2013, at 3:24 AM, Chris Mylonas wrote:

> Thanks, but no again.
> 
> 
> form.recordError(commonNameField, "The ip address you entered is public and
> in use - please try again or search for it ${" + link.toAbsoluteURI() + "}"
> );
> 
> renders this as a string, and without the expansion-y ${} it's just plain
> old text.
> ${http://hplaptop:8080/MetwideSubnetsWeb/search/ipaddress}
> 
> 
> Similarly putting an <a href=\" + Link#toAbsoluteURI + \">blah</a>  just
> outputs text, like this:
> 
> &lt;a href="${http://hplaptop:8080/MetwideSubnetsWeb/search/ipaddress}"&gt;
> blah&lt;/a&gt;
> 
> (I've copy pasted html src.  In case it's not viewable, tapestry has
> converted the less than and greater than in the previous sentence to
> ampersand+elle+tee+semi-colon and ampersand+gee+tee+semi-colon,
> respectively)
> 
> 
> Form#recordError accepts a String.  So I'm starting to think this String is
> just rendered without any smarts to it.  Can't really fuse in a
> MarkupWriter, because recordError just accepts String.
> 
> 
> Any further ideas?
> 
> Can the Corelib.Errors component, rather than just being
> <t:errors />
> 
> be expanded to hold a <t:if> and ${expansion} for use in case of error?
> 
> Cheers
> Chris
> 
> 
> On Thu, Dec 19, 2013 at 2:26 AM, Taha Siddiqi <ta...@gmail.com>wrote:
> 
>> Use Link#toAbsoluteURI() or Link#toURI() depending on your need( I think
>> here toAbsoluteURI() is more appropriate)
>> 
>> 
>> On Dec 18, 2013, at 8:32 PM, Chris Mylonas wrote:
>> 
>>> Thanks Taha - I was looking at the Link Component FAQ earlier scratching
>> my
>>> head.  It spits out the text for the link, not a html link.
>>> 
>>> So I tried this:
>>>           Link link = linkSource.createPageRenderLink(IPAddress.class);
>>>           if (ni != null) {
>>>               form.recordError(commonNameField, "The ip address you
>>> entered is public and in use - please try again or search for it <a
>>> href=\"" + link + "\">HERE</a>" );
>>>           }
>>> 
>>> and that just spits out text too.
>>> 
>>> 
>>> 
>>> Given it's 2am, I'm going to bed.  Try again tomorrow with a fresh head.
>>> Cheers,
>>> Chris
>>> 
>>> 
>>> 
>>> 
>>> On Wed, Dec 18, 2013 at 4:25 PM, Taha Hafeez Siddiqi <
>>> tawus.tapestry@gmail.com> wrote:
>>> 
>>>> You can use
>>>> 
>>>> 
>>>> 
>> http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/services/PageRenderLinkSource.html#createPageRenderLink(java.lang.Class)
>>>> 
>>>> 
>>>> @Inject
>>>> private PageRenderLinkSource linkSource
>>>> 
>>>> form.recordError(someField, "my link is " +
>>>> linkSource.createPageRenderLink(MyPage.class));
>>>> 
>>>> there are other variants of createPageRenderLink which can take context
>>>> parameters.
>>>> 
>>>> regards
>>>> Taha
>>>> 
>>>> On 18-Dec-2013, at 8:18 AM, Chris Mylonas <ch...@opencsta.org> wrote:
>>>> 
>>>>> Hi Tapestry Users,
>>>>> 
>>>>> What is the best way to include a link to a page from the java class?
>>>>> 
>>>>> I have a form, returning an error that states: "The ip address you
>>>> entered
>>>>> is public and in use - please try again or search for it to see it's
>>>>> current use"
>>>>> 
>>>>> I would like to put a link in that error message to the search page.
>>>>> 
>>>>> It's just a standard form.recordErrors
>>>>> 
>>>>>              form.recordError(commonNameField, "The ip address you
>>>>> entered is public and in use - please try again or search (PUT LINK
>> HERE
>>>> TO
>>>>> SEARCH PAGE) for it to see it's current use");
>>>>> 
>>>>> Cheers
>>>>> Chris
>>>> 
>>>> 
>> 
>> 


Re: My form error message, include link to a page from java class

Posted by Chris Mylonas <ch...@opencsta.org>.
Thanks, but no again.


form.recordError(commonNameField, "The ip address you entered is public and
in use - please try again or search for it ${" + link.toAbsoluteURI() + "}"
);

renders this as a string, and without the expansion-y ${} it's just plain
old text.
${http://hplaptop:8080/MetwideSubnetsWeb/search/ipaddress}


Similarly putting an <a href=\" + Link#toAbsoluteURI + \">blah</a>  just
outputs text, like this:

&lt;a href="${http://hplaptop:8080/MetwideSubnetsWeb/search/ipaddress}"&gt;
blah&lt;/a&gt;

(I've copy pasted html src.  In case it's not viewable, tapestry has
converted the less than and greater than in the previous sentence to
ampersand+elle+tee+semi-colon and ampersand+gee+tee+semi-colon,
respectively)


Form#recordError accepts a String.  So I'm starting to think this String is
just rendered without any smarts to it.  Can't really fuse in a
MarkupWriter, because recordError just accepts String.


Any further ideas?

Can the Corelib.Errors component, rather than just being
<t:errors />

be expanded to hold a <t:if> and ${expansion} for use in case of error?

Cheers
Chris


On Thu, Dec 19, 2013 at 2:26 AM, Taha Siddiqi <ta...@gmail.com>wrote:

> Use Link#toAbsoluteURI() or Link#toURI() depending on your need( I think
> here toAbsoluteURI() is more appropriate)
>
>
> On Dec 18, 2013, at 8:32 PM, Chris Mylonas wrote:
>
> > Thanks Taha - I was looking at the Link Component FAQ earlier scratching
> my
> > head.  It spits out the text for the link, not a html link.
> >
> > So I tried this:
> >            Link link = linkSource.createPageRenderLink(IPAddress.class);
> >            if (ni != null) {
> >                form.recordError(commonNameField, "The ip address you
> > entered is public and in use - please try again or search for it <a
> > href=\"" + link + "\">HERE</a>" );
> >            }
> >
> > and that just spits out text too.
> >
> >
> >
> > Given it's 2am, I'm going to bed.  Try again tomorrow with a fresh head.
> > Cheers,
> > Chris
> >
> >
> >
> >
> > On Wed, Dec 18, 2013 at 4:25 PM, Taha Hafeez Siddiqi <
> > tawus.tapestry@gmail.com> wrote:
> >
> >> You can use
> >>
> >>
> >>
> http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/services/PageRenderLinkSource.html#createPageRenderLink(java.lang.Class)
> >>
> >>
> >> @Inject
> >> private PageRenderLinkSource linkSource
> >>
> >> form.recordError(someField, "my link is " +
> >> linkSource.createPageRenderLink(MyPage.class));
> >>
> >> there are other variants of createPageRenderLink which can take context
> >> parameters.
> >>
> >> regards
> >> Taha
> >>
> >> On 18-Dec-2013, at 8:18 AM, Chris Mylonas <ch...@opencsta.org> wrote:
> >>
> >>> Hi Tapestry Users,
> >>>
> >>> What is the best way to include a link to a page from the java class?
> >>>
> >>> I have a form, returning an error that states: "The ip address you
> >> entered
> >>> is public and in use - please try again or search for it to see it's
> >>> current use"
> >>>
> >>> I would like to put a link in that error message to the search page.
> >>>
> >>> It's just a standard form.recordErrors
> >>>
> >>>               form.recordError(commonNameField, "The ip address you
> >>> entered is public and in use - please try again or search (PUT LINK
> HERE
> >> TO
> >>> SEARCH PAGE) for it to see it's current use");
> >>>
> >>> Cheers
> >>> Chris
> >>
> >>
>
>

Re: My form error message, include link to a page from java class

Posted by Taha Siddiqi <ta...@gmail.com>.
Use Link#toAbsoluteURI() or Link#toURI() depending on your need( I think here toAbsoluteURI() is more appropriate)


On Dec 18, 2013, at 8:32 PM, Chris Mylonas wrote:

> Thanks Taha - I was looking at the Link Component FAQ earlier scratching my
> head.  It spits out the text for the link, not a html link.
> 
> So I tried this:
>            Link link = linkSource.createPageRenderLink(IPAddress.class);
>            if (ni != null) {
>                form.recordError(commonNameField, "The ip address you
> entered is public and in use - please try again or search for it <a
> href=\"" + link + "\">HERE</a>" );
>            }
> 
> and that just spits out text too.
> 
> 
> 
> Given it's 2am, I'm going to bed.  Try again tomorrow with a fresh head.
> Cheers,
> Chris
> 
> 
> 
> 
> On Wed, Dec 18, 2013 at 4:25 PM, Taha Hafeez Siddiqi <
> tawus.tapestry@gmail.com> wrote:
> 
>> You can use
>> 
>> 
>> http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/services/PageRenderLinkSource.html#createPageRenderLink(java.lang.Class)
>> 
>> 
>> @Inject
>> private PageRenderLinkSource linkSource
>> 
>> form.recordError(someField, "my link is " +
>> linkSource.createPageRenderLink(MyPage.class));
>> 
>> there are other variants of createPageRenderLink which can take context
>> parameters.
>> 
>> regards
>> Taha
>> 
>> On 18-Dec-2013, at 8:18 AM, Chris Mylonas <ch...@opencsta.org> wrote:
>> 
>>> Hi Tapestry Users,
>>> 
>>> What is the best way to include a link to a page from the java class?
>>> 
>>> I have a form, returning an error that states: "The ip address you
>> entered
>>> is public and in use - please try again or search for it to see it's
>>> current use"
>>> 
>>> I would like to put a link in that error message to the search page.
>>> 
>>> It's just a standard form.recordErrors
>>> 
>>>               form.recordError(commonNameField, "The ip address you
>>> entered is public and in use - please try again or search (PUT LINK HERE
>> TO
>>> SEARCH PAGE) for it to see it's current use");
>>> 
>>> Cheers
>>> Chris
>> 
>> 


Re: My form error message, include link to a page from java class

Posted by Chris Mylonas <ch...@opencsta.org>.
Thanks Taha - I was looking at the Link Component FAQ earlier scratching my
head.  It spits out the text for the link, not a html link.

So I tried this:
            Link link = linkSource.createPageRenderLink(IPAddress.class);
            if (ni != null) {
                form.recordError(commonNameField, "The ip address you
entered is public and in use - please try again or search for it <a
href=\"" + link + "\">HERE</a>" );
            }

and that just spits out text too.



Given it's 2am, I'm going to bed.  Try again tomorrow with a fresh head.
Cheers,
Chris




On Wed, Dec 18, 2013 at 4:25 PM, Taha Hafeez Siddiqi <
tawus.tapestry@gmail.com> wrote:

> You can use
>
>
> http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/services/PageRenderLinkSource.html#createPageRenderLink(java.lang.Class)
>
>
> @Inject
> private PageRenderLinkSource linkSource
>
> form.recordError(someField, "my link is " +
> linkSource.createPageRenderLink(MyPage.class));
>
> there are other variants of createPageRenderLink which can take context
> parameters.
>
> regards
> Taha
>
> On 18-Dec-2013, at 8:18 AM, Chris Mylonas <ch...@opencsta.org> wrote:
>
> > Hi Tapestry Users,
> >
> > What is the best way to include a link to a page from the java class?
> >
> > I have a form, returning an error that states: "The ip address you
> entered
> > is public and in use - please try again or search for it to see it's
> > current use"
> >
> > I would like to put a link in that error message to the search page.
> >
> > It's just a standard form.recordErrors
> >
> >                form.recordError(commonNameField, "The ip address you
> > entered is public and in use - please try again or search (PUT LINK HERE
> TO
> > SEARCH PAGE) for it to see it's current use");
> >
> > Cheers
> > Chris
>
>

Re: My form error message, include link to a page from java class

Posted by Taha Hafeez Siddiqi <ta...@gmail.com>.
You can use 

http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/services/PageRenderLinkSource.html#createPageRenderLink(java.lang.Class)


@Inject
private PageRenderLinkSource linkSource

form.recordError(someField, "my link is " + linkSource.createPageRenderLink(MyPage.class));

there are other variants of createPageRenderLink which can take context parameters.

regards
Taha

On 18-Dec-2013, at 8:18 AM, Chris Mylonas <ch...@opencsta.org> wrote:

> Hi Tapestry Users,
> 
> What is the best way to include a link to a page from the java class?
> 
> I have a form, returning an error that states: "The ip address you entered
> is public and in use - please try again or search for it to see it's
> current use"
> 
> I would like to put a link in that error message to the search page.
> 
> It's just a standard form.recordErrors
> 
>                form.recordError(commonNameField, "The ip address you
> entered is public and in use - please try again or search (PUT LINK HERE TO
> SEARCH PAGE) for it to see it's current use");
> 
> Cheers
> Chris