Dear Sir,

I have done it through the following way, though there is an error
which I will mention at the last.

My solution...

controller.xml
_____________________
<request-map uri="goToWebsite">
        <security https="true" auth="true"/>
        <event type="java"
path="com.akm.exim.events.CallExternalWebsite"
invoke="callExternalWebsite"/>
        <response name="success" type="url-redirect" value="DomCustomerList"/>
        <response name="error" type="view" value="errorPage"/>
    </request-map>
_____________________

CallExternalWebsite java file
----------------------------------
public class CallExternalWebsite {
public static final String module = CallExternalWebsite.class.getName();

 public static String callExternalWebsite(HttpServletRequest request,
HttpServletResponse response) {

//Delegator delegator = (Delegator) request.getAttribute("delegator");
     //LocalDispatcher dispatcher = (LocalDispatcher)
request.getAttribute("dispatcher");
     //GenericValue userLogin = (GenericValue)
request.getSession().getAttribute("userLogin");
//Map<String, Object> result = ServiceUtil.returnSuccess();

Map<String, Object> parameters = UtilHttp.getParameterMap(request); //
To get parameters from ftl file

String url = parameters.get("customerWebsite").toString().trim();
String os = System.getProperty("os.name").toLowerCase();
     Runtime rt = Runtime.getRuntime();

Debug.logInfo("=======url=========", url);

try {
if (os.indexOf( "win" ) >= 0) {
        // this doesn't support showing urls in the form of "page.html#nameLink"
        rt.exec( "rundll32 url.dll, FileProtocolHandler " + url);
    } else if (os.indexOf( "mac" ) >= 0) {
        rt.exec( "open " + url);
            } else if (os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0) {
        // Do a best guess on unix until we get a platform independent way
        // Build a list of browsers to try, in this order.
        String[] browsers = {"epiphany", "firefox", "mozilla", "konqueror",
                     "netscape","opera","links","lynx"};
        // Build a command string which looks like "browser1 "url" ||
browser2 "url" ||..."
        StringBuffer cmd = new StringBuffer();
        for (int i=0; i<browsers.length; i++)
            cmd.append( (i==0  ? "" : " || " ) + browsers[i] +" \"" +
url + "\" ");
        rt.exec(new String[] { "sh", "-c", cmd.toString() });
           } else {
           request.setAttribute("_EVENT_MESSAGE_", url);
           }
}
catch (Exception e) {
String errMsg = "Unable to open url." + e.toString();
            request.setAttribute("_ERROR_MESSAGE_", errMsg);
            return "error";
}
        //request.setAttribute("_EVENT_MESSAGE_", url);
        return "success";
    }
}
----------------------------------

On Sat, May 7, 2022 at 1:18 PM Jacques Le Roux
<[email protected]> wrote:
>
> Hi,
>
> That's why I recommended initially to read the "documentation", ie the 
> related content in site-conf.xsd:
>
>                      <xs:enumeration value="url">
>                          <xs:annotation>
>                              <xs:documentation>
>                                  Any URL, relative or absolute. Redirected 
> parameters are not used, you can put them in the url.
>                              </xs:documentation>
>                          </xs:annotation>
>                      </xs:enumeration>
>                      <xs:enumeration value="url-redirect">
>                          <xs:annotation>
>                              <xs:documentation>
>                                  Works like URL but you can also pass 
> redirected parameters.
>                              </xs:documentation>
>                          </xs:annotation>
>                      </xs:enumeration>
>
> As you can see these features don't allow dynamic URLs. What you can do is 
> something like:
>
>          <actions>
>              <set field="targetUrl" 
> value="https://github.com/apache/ofbiz-framework"/> (here you need to 
> dynamically set the value, like by using
> "${groovy:........", see examples in code - none about URL though)
>          </actions>
>
> [...]
>
>     <field name="supplierWebsite" title="${uiLabelMap.supplierWebsite}">
>          <hyperlink target="${targetUrl}" target-window="_BLANK" 
> description="${supplierWebsite}" also-hidden="false"/>
>     </field>
>
> I did not try it, but it should work.
>
> HTH
>
> Jacques
>
> Le 07/05/2022 à 05:52, Avijit Bose a écrit :
> > Hello Sir,
> >
> > Your "<response name="success" type="url"
> > value="https://github.com/apache/ofbiz-framework"/>" is working. It is
> > going to the external site, but the value is hard coded as
> > "https://github.com/apache/ofbiz-framework";.
> >
> > I am trying to set this value like this....but unable to set the
> > supplierWebsite value in the "value" field.
> >
> > <request-map uri="goToWebsite">
> >          <security https="true" auth="true"/>
> >          <response name="success" type="url" value="supplierWebsite">
> >                <redirect-parameter name="supplierWebsite"/>
> >          </response>
> > </request-map>
> >
> > My form is like this...
> >
> > <field name="supplierWebsite" title="${uiLabelMap.supplierWebsite}">
> >          <hyperlink target="goToWebsite"  target-window="_BLANK"
> > description="${supplierWebsite}" also-hidden="false">
> >                   <parameter param-name="supplierWebsite"/>
> >          </hyperlink>
> > </field>
> >
> > How can I set dynamic value in the "value" attribute of the "response"
> > tag? Pls help.
> >
> > On Fri, May 6, 2022 at 12:46 PM Jacques Le Roux
> > <[email protected]>  wrote:
> >> Hi,
> >>
> >> You can do something like that in your controller
> >>
> >>       <request-map uri="testUrl">
> >>           <security https="true" auth="true"/>
> >>           <response name="success" type="url" 
> >> value="https://github.com/apache/ofbiz-framework"/>
> >>       </request-map>
> >>
> >> Jacques
> >>
> >> Le 06/05/2022 à 03:11, Avijit Bose a écrit :
> >>> Dear Sir,
> >>>
> >>> Unable to do so. Pls help with the code.
> >>>
> >>> regards
> >>> Avijit
> >>>
> >>> On Thu, May 5, 2022 at 11:52 AM Jacques Le Roux
> >>> <[email protected]>  wrote:
> >>>> Hi Avijit
> >>>>
> >>>> TL;DR: use the "url" response type
> >>>>
> >>>> You could have helped yourself. If you look into a controller file you 
> >>>> will see its related schemaLocation: site-conf.xsd
> >>>>
> >>>> In site-conf.xsd you can find under response element (for reques-map 
> >>>> element) the possible types, "url" is there explained.
> >>>>
> >>>> A faster way, if you use an IDE (I guess you do), is to hover over the 
> >>>> reques-map response type and you will see "url", though there there is no
> >>>> explanation shown
> >>>>
> >>>> HTH
> >>>>
> >>>> Jacques
> >>>>
> >>>> Le 05/05/2022 à 03:59, Avijit Bose a écrit :
> >>>>> Hello,
> >>>>>
> >>>>> My form list is as follows:
> >>>>> ----------------------------------------------------------------------------------------------------------------------------
> >>>>> <form name="ListSuppliers" type="list" list-name="listIt"
> >>>>> paginate-target="FindSuppliers"
> >>>>>            default-entity-name="AkmSupplier" separate-columns="true"
> >>>>> odd-row-style="alternate-row"
> >>>>>            header-row-style="header-row-2"
> >>>>> default-table-style="basic-table hover-bar">
> >>>>>            <actions>
> >>>>>                   <service service-name="performFind" 
> >>>>> result-map="result"
> >>>>> result-map-list="listIt">
> >>>>> <field-map field-name="inputFields" from-field="eximCtx"/>
> >>>>> <field-map field-name="entityName" value="AkmSupplier"/>
> >>>>> <field-map field-name="orderBy" from-field="parameters.sortField"/>
> >>>>> <field-map field-name="viewIndex" from-field="viewIndex"/>
> >>>>> <field-map field-name="viewSize" from-field="viewSize"/>
> >>>>> </service>
> >>>>>            </actions>
> >>>>>
> >>>>>            <field name="supplierWebsite" 
> >>>>> title="${uiLabelMap.supplierWebsite}">
> >>>>>            <hyperlink target="external" description="${supplierWebsite}"
> >>>>> also-hidden="false">
> >>>>>            <parameter param-name="supplierWebsite"/>
> >>>>>            </hyperlink>
> >>>>>            </field>
> >>>>>            </form>
> >>>>> -----------------------------------------------------------------------------------------------------------------
> >>>>>
> >>>>> ${supplierWebsite} in the above form ishttp://www.abconsultancy.co.in
> >>>>> which is an external website.
> >>>>>
> >>>>> While clicking the above link in the form, it is taking through the
> >>>>> controller. I want to open the external website directly bypassing the
> >>>>> controller and in a different window.
> >>>>>
> >>>>> Pls help.
> >>>>>
> >>>>> regards
> >>>>> Avijit Bose

Reply via email to